package vue;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.SpinnerNumberModel;

import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.border.TitledBorder;
import javax.swing.UIManager;
import javax.swing.JCheckBox;
import javax.swing.JSpinner;
import javax.swing.JButton;

import controleur.HomeController;
import controleur.PasserCommandeController;


import javax.swing.JTable;

import modele.Commande;
import modele.Produit;

import org.jdesktop.beansbinding.Bindings;
import org.jdesktop.beansbinding.BeanProperty;
import java.util.List;
import modele.LigneCommande;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
import org.jdesktop.beansbinding.AutoBinding;
@SuppressWarnings("serial")
public class PasserCommande extends JFrame {

	private JPanel contentPane;
	private ModeDePaiement mdp=new ModeDePaiement();
	private ParCarteBancaire pcb= new ParCarteBancaire();
	private Recapitulatif recapt= new Recapitulatif();
	private static Accueilbis accueil;
	public static Accueilbis getAccueil() {
		return accueil;
	}

	public static void setAccueil(Accueilbis accueil) {
		PasserCommande.accueil = accueil;
	}

	public Recapitulatif getRecapt() {
		return recapt;
	}

	public void setRecapt(Recapitulatif recapt) {
		this.recapt = recapt;
	}


	private Commande commande= new Commande();

	private JButton btnValider;
	
	private JCheckBox chckbxCoca;
	private JCheckBox chckbxFanta;
	private JCheckBox chckbxSprite;
	private JCheckBox chckbxFrites;
	private JCheckBox chckbxDoublecheese;
	private JCheckBox chckbxChicken;
	private JCheckBox chckbxChickenMditranne;
	private JCheckBox chckbxCake;
	private JCheckBox chckbxTiramissu;
	

	private JSpinner spinnerCoca;
	private JSpinner spinnerFanta;
	private JSpinner spinnerSprite;
	private JSpinner spinnerFrites;
	private JSpinner spinnerDoubleCheese;
	private JSpinner spinnerChickenCurry;
	private JSpinner spinnerChickenMediter;
	private JSpinner spinnerCake;
	private JSpinner spinnerTiramissu;

	private JTable tableCommande;
	private HomeController hmctrl;

	private PasserCommandeController cmdcntrl;

	public PasserCommandeController getCmdcntrl() {
		return cmdcntrl;
	}

	public void setCmdcntrl(PasserCommandeController cmdcntrl) {
		this.cmdcntrl = cmdcntrl;
	}


	private SpinnerNumberModel cocaModel=new SpinnerNumberModel(0, 0, null, 1);
	private SpinnerNumberModel fantaModel=new SpinnerNumberModel(0, 0, null, 1);
	private SpinnerNumberModel fritesModel=new SpinnerNumberModel(0, 0, null, 1);
	private SpinnerNumberModel spriteModel=new SpinnerNumberModel(0, 0, null, 1);
	private SpinnerNumberModel doubleCheeseModel=new SpinnerNumberModel(0, 0, null, 1);
	private SpinnerNumberModel chickenCurryModel=new SpinnerNumberModel(0, 0, null, 1);
	private SpinnerNumberModel chickenMediterModel=new SpinnerNumberModel(0, 0, null, 1);
	private SpinnerNumberModel cakeModel=new SpinnerNumberModel(0, 0, null, 1);
	private SpinnerNumberModel tiramissuModel=new SpinnerNumberModel(0, 0, null, 1);
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					PasserCommande frame = new PasserCommande();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public PasserCommande() {
		//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//setValues();
		this.accueil=accueil;
		setBounds(100, 100, 500, 423);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new CardLayout(0, 0));
		
		JPanel panel_4 = new JPanel();
		panel_4.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Votre commande", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		contentPane.add(panel_4, "name_12557479633071");
		panel_4.setLayout(null);
		
	    btnValider = new JButton("Valider");
		btnValider.setBounds(187, 321, 89, 23);
		panel_4.add(btnValider);
		
		JPanel panel = new JPanel();
		panel.setBounds(6, 16, 120, 151);
		panel_4.add(panel);
		panel.setBorder(new TitledBorder(null, "Boissons", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel.setLayout(null);
		
	    chckbxCoca = new JCheckBox("Coca");
		chckbxCoca.setBounds(0, 34, 55, 23);
		panel.add(chckbxCoca);
		//chckbxCoca.addActionListener(new ChckbxCocaListener());
		
		spinnerCoca = new JSpinner(cocaModel);		
		spinnerCoca.setBounds(59, 35, 40, 20);
		panel.add(spinnerCoca);
		
		chckbxFanta = new JCheckBox("Fanta");
		chckbxFanta.setBounds(0, 60, 55, 23);
		panel.add(chckbxFanta);
		
		spinnerFanta = new JSpinner(fantaModel);
		spinnerFanta.setBounds(59, 64, 40, 20);
		panel.add(spinnerFanta);
		
		chckbxSprite = new JCheckBox("Sprite");
		chckbxSprite.setBounds(0, 94, 53, 23);
		panel.add(chckbxSprite);
		
		spinnerSprite = new JSpinner(spriteModel);
		spinnerSprite.setBounds(59, 95, 40, 20);
		panel.add(spinnerSprite);
		
		JPanel panel_3 = new JPanel();
		panel_3.setBounds(134, 188, 335, 122);
		panel_4.add(panel_3);
		panel_3.setBorder(new TitledBorder(null, "Recapitulatif", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_3.setLayout(null);
		
		tableCommande = new JTable();
		tableCommande.setBounds(10, 22, 315, 89);
		panel_3.add(tableCommande);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBounds(134, 16, 335, 151);
		panel_4.add(panel_1);
		panel_1.setBorder(new TitledBorder(null, "Menus", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_1.setLayout(null);
		
		chckbxFrites = new JCheckBox("Frites");
		chckbxFrites.setBounds(6, 23, 53, 23);
		panel_1.add(chckbxFrites);
		
		spinnerFrites = new JSpinner(fritesModel);
		spinnerFrites.setBounds(65, 24, 40, 20);
		panel_1.add(spinnerFrites);
		
		chckbxDoublecheese = new JCheckBox("DoubleCheese");
		chckbxDoublecheese.setBounds(117, 23, 97, 23);
		panel_1.add(chckbxDoublecheese);
			
		spinnerDoubleCheese = new JSpinner(doubleCheeseModel);
		spinnerDoubleCheese.setBounds(220, 24, 40, 20);
		panel_1.add(spinnerDoubleCheese);
		
		chckbxChicken = new JCheckBox("Chicken Curry");
		chckbxChicken.setBounds(6, 61, 97, 23);
		panel_1.add(chckbxChicken);
		
		spinnerChickenCurry = new JSpinner(chickenCurryModel);
		spinnerChickenCurry.setBounds(109, 62, 40, 20);
		panel_1.add(spinnerChickenCurry);
		
		chckbxChickenMditranne = new JCheckBox("Chicken M\u00E9dit\u00E9rann\u00E9e");
		chckbxChickenMditranne.setBounds(152, 61, 139, 23);
		panel_1.add(chckbxChickenMditranne);
		
		spinnerChickenMediter = new JSpinner(chickenMediterModel);
		spinnerChickenMediter.setBounds(296, 62, 40, 20);
		panel_1.add(spinnerChickenMediter);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBounds(6, 178, 120, 132);
		panel_4.add(panel_2);
		panel_2.setBorder(new TitledBorder(null, "Desserts", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_2.setLayout(null);
		
		chckbxCake = new JCheckBox("Cake");
		chckbxCake.setBounds(0, 21, 49, 23);
		panel_2.add(chckbxCake);
		
		spinnerCake = new JSpinner(cakeModel);
		spinnerCake.setBounds(52, 22, 40, 20);
		panel_2.add(spinnerCake);
		
		chckbxTiramissu = new JCheckBox("Tiramissu");
		chckbxTiramissu.setBounds(0, 49, 69, 23);
		panel_2.add(chckbxTiramissu);
		
		spinnerTiramissu = new JSpinner(tiramissuModel);
		spinnerTiramissu.setBounds(75, 50, 40, 20);
		panel_2.add(spinnerTiramissu);
		contentPane.add(mdp, "name_12557505717604");
		contentPane.add(pcb,"name_pcb");
		contentPane.add(recapt,"name_recapt");
	    cmdcntrl= new PasserCommandeController(this);
	 //initDataBindings();
		
	}

	
	public HomeController getHmctrl() {
		return hmctrl;
	}

	public void setHmctrl(HomeController hmctrl) {
		this.hmctrl = hmctrl;
	}

	public ModeDePaiement getMdp() {
		return mdp;
	}

	public void setMdp(ModeDePaiement mdp) {
		this.mdp = mdp;
	}
	
	public JButton getBtnValider() {
		return btnValider;
	}

	public void setBtnValider(JButton btnValider) {
		this.btnValider = btnValider;
	}
	

	public JSpinner getSpinnerCoca() {
		return spinnerCoca;
	}

	public void setSpinnerCoca(JSpinner spinnerCoca) {
		this.spinnerCoca = spinnerCoca;
	}

	public JCheckBox getChckbxCoca() {
		return chckbxCoca;
	}

	public void setChckbxCoca(JCheckBox chckbxCoca) {
		this.chckbxCoca = chckbxCoca;
	}

	public JCheckBox getChckbxFanta() {
		return chckbxFanta;
	}

	public void setChckbxFanta(JCheckBox chckbxFanta) {
		this.chckbxFanta = chckbxFanta;
	}

	public JCheckBox getChckbxSprite() {
		return chckbxSprite;
	}

	public void setChckbxSprite(JCheckBox chckbxSprite) {
		this.chckbxSprite = chckbxSprite;
	}

	public JCheckBox getChckbxFrites() {
		return chckbxFrites;
	}

	public void setChckbxFrites(JCheckBox chckbxFrites) {
		this.chckbxFrites = chckbxFrites;
	}

	public JCheckBox getChckbxDoublecheese() {
		return chckbxDoublecheese;
	}

	public void setChckbxDoublecheese(JCheckBox chckbxDoublecheese) {
		this.chckbxDoublecheese = chckbxDoublecheese;
	}

	public JCheckBox getChckbxChicken() {
		return chckbxChicken;
	}

	public void setChckbxChicken(JCheckBox chckbxChicken) {
		this.chckbxChicken = chckbxChicken;
	}

	public JCheckBox getChckbxChickenMditranne() {
		return chckbxChickenMditranne;
	}

	public void setChckbxChickenMditranne(JCheckBox chckbxChickenMditranne) {
		this.chckbxChickenMditranne = chckbxChickenMditranne;
	}

	public JCheckBox getChckbxCake() {
		return chckbxCake;
	}

	public void setChckbxCake(JCheckBox chckbxCake) {
		this.chckbxCake = chckbxCake;
	}

	public JCheckBox getChckbxTiramissu() {
		return chckbxTiramissu;
	}

	public void setChckbxTiramissu(JCheckBox chckbxTiramissu) {
		this.chckbxTiramissu = chckbxTiramissu;
	}

	public JSpinner getSpinnerFanta() {
		return spinnerFanta;
	}

	public void setSpinnerFanta(JSpinner spinnerFanta) {
		this.spinnerFanta = spinnerFanta;
	}

	public JSpinner getSpinnerSprite() {
		return spinnerSprite;
	}

	public void setSpinnerSprite(JSpinner spinnerSprite) {
		this.spinnerSprite = spinnerSprite;
	}

	public JSpinner getSpinnerFrites() {
		return spinnerFrites;
	}

	public void setSpinnerFrites(JSpinner spinnerFrites) {
		this.spinnerFrites = spinnerFrites;
	}

	public JSpinner getSpinnerDoubleCheese() {
		return spinnerDoubleCheese;
	}

	public void setSpinnerDoubleCheese(JSpinner spinnerDoubleCheese) {
		this.spinnerDoubleCheese = spinnerDoubleCheese;
	}

	public JSpinner getSpinnerChickenCurry() {
		return spinnerChickenCurry;
	}

	public void setSpinnerChickenCurry(JSpinner spinnerChickenCurry) {
		this.spinnerChickenCurry = spinnerChickenCurry;
	}

	public JSpinner getSpinnerChickenMediter() {
		return spinnerChickenMediter;
	}

	public void setSpinnerChickenMediter(JSpinner spinnerChickenMediter) {
		this.spinnerChickenMediter = spinnerChickenMediter;
	}

	public JSpinner getSpinnerCake() {
		return spinnerCake;
	}

	public void setSpinnerCake(JSpinner spinnerCake) {
		this.spinnerCake = spinnerCake;
	}

	public JSpinner getSpinnerTiramissu() {
		return spinnerTiramissu;
	}

	public void setSpinnerTiramissu(JSpinner spinnerTiramissu) {
		this.spinnerTiramissu = spinnerTiramissu;
	}

	public JTable getTableCommande() {
		return tableCommande;
	}

	public void setTableCommande(JTable tableCommande) {
		this.tableCommande = tableCommande;
	}
	
	
	protected void initDataBindings() {
		BeanProperty<Commande, List<LigneCommande>> commandeBeanProperty = BeanProperty.create("lignesDeCommandes");
		JTableBinding<LigneCommande, Commande, JTable> jTableBinding = SwingBindings.createJTableBinding(UpdateStrategy.READ, commande, commandeBeanProperty, tableCommande);
		//
		BeanProperty<LigneCommande, String> ligneCommandeBeanProperty = BeanProperty.create("produit.nom");
		jTableBinding.addColumnBinding(ligneCommandeBeanProperty).setColumnName("Nom").setEditable(false);
		//
		BeanProperty<LigneCommande, Double> ligneCommandeBeanProperty_1 = BeanProperty.create("produit.prix");
		jTableBinding.addColumnBinding(ligneCommandeBeanProperty_1).setColumnName("Prix unitaire").setEditable(false);
		//
		BeanProperty<LigneCommande, Integer> ligneCommandeBeanProperty_2 = BeanProperty.create("quantite");
		jTableBinding.addColumnBinding(ligneCommandeBeanProperty_2).setColumnName("Quantit\u00E9").setEditable(false);
		//
		BeanProperty<LigneCommande, Float> ligneCommandeBeanProperty_3 = BeanProperty.create("total");
		jTableBinding.addColumnBinding(ligneCommandeBeanProperty_3).setColumnName("Total").setEditable(false);
		//
		jTableBinding.setEditable(false);
		jTableBinding.bind();
	}
}
